package com.spark.gaea.base;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.util.List;

public class Page<T> implements Serializable {
	@JsonIgnore
	private Integer page;
	@JsonIgnore
	private Integer pagesize;
	@JsonIgnore
	private List<String> order;
	private List<T> list;
	private Integer count;

	@JsonIgnore
	public int getStartIndex() {
		int startIndex = 0;
		final int pageSizeVal = this.getPagesize();
		if (pageSizeVal == 0) {
			startIndex = 0;
		} else if (this.page != null) {
			final int pageNum = this.page;
			if (pageNum > 0) {
				startIndex = pageSizeVal * (pageNum - 1);
			}
		}
		return startIndex;
	}

	public List<String> getOrder() {
		return this.order;
	}

	public void setOrder(final List<String> order) {
		this.order = order;
	}

	public Integer getPage() {
		return this.page;
	}

	public void setPage(final Integer page) {
		this.page = page;
	}

	public Integer getPagesize() {
		return this.pagesize;
	}

	public void setPagesize(final Integer pagesize) {
		this.pagesize = pagesize;
	}

	public List<T> getList() {
		return this.list;
	}

	public void setList(final List<T> list) {
		this.list = list;
	}

	public void setList(final List<T> responses, final Integer count) {
		this.list = responses;
		this.count = count;
	}

	public Integer getCount() {
		if (this.count != null) {
			return this.count;
		}
		if (this.list != null) {
			return this.list.size();
		}
		return null;
	}
}
